#根文件目录下载文件，不会重复下载。可以在错误后，继续补充下载

import os 
import requests
from time import sleep, time
import datetime

def downFile(urlpath,savepath):
    r = requests.get(urlpath)
    with open(savepath, "wb") as code:
      code.write(r.content)


def ToTime(seconds):
    if(seconds>=3600):
        hour=int((seconds-(seconds % 3600))/3600)
        min=int((seconds- hour*3600 -(seconds % 60))/60)
        s=seconds%60
        return str(hour)+'小时'+str(min)+"分"+str(s)+'秒'
    else:
        min=int((seconds - (seconds%60))/60)
        s=seconds%60
        return str(min)+"分"+str(s)+'秒'

data=''
with open ('文件目录.txt','r',encoding='utf-8') as f:
    data=f.readlines()

downLoadCount=0

dirList=[]
for item in data:
    downLoadCount=downLoadCount+1

    if(item.find('.')!=-1):
        try:
            x=item.strip()
            if( not os.path.exists('./element ui/'+x)):
                downFile('https://unpkg.com/browse/element-ui@2.15.3/'+x,'./element ui/'+x)
                print('下载完成：'+x)

                shengyu=len(data)-downLoadCount
                print('剩余：'+str(shengyu))
                print('预计完成时间:'+ToTime(shengyu*6))
                sleep(6)
            else:
                print('已存在：'+x)
        except Exception as ex:
            print('下载错误:'+str(ex))
